package com.gree.scmservice.dao.saasDao;

import com.gree.common.entity.TablePageData;
import com.gree.framework.entity.SaasTenant;
import com.gree.scmservice.entity.saas.SaasSysOrder;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.pager.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by 180686 on 2021/9/8 8:54
 */
@Repository
public class SaasTenantDao {

    @Autowired
    private Dao dao;

    public SaasTenant insertSaasSysTenant(SaasTenant saasSysTenant){
        SaasTenant insert = dao.insert(saasSysTenant);
        return insert;
    }

    public int deleteSaasSysTenantById(Long tenantId){
        int delete = dao.clear(SaasTenant.class, Cnd.where("tenant_id", "=", tenantId));
        return delete;
    }

    public int deleteSaasSysTenantByIds(Long[] tenantIds){
        int delete = dao.clear(SaasTenant.class, Cnd.where("tenant_id", "in", tenantIds));
        return delete;
    }

    public int updateSaasSysTenant(SaasTenant saasSysTenant){
        int update = dao.update(saasSysTenant);
        return update;
    }

    public SaasTenant selectSaasSysTenantById(String tenantId){
        SaasTenant fetch = dao.fetch(SaasTenant.class, tenantId);
        return fetch;
    }

    public TablePageData<SaasTenant> selectSaasSysTenantList(SaasTenant saasSysTenant){
        Pager pager = dao.createPager(saasSysTenant.getPageNum(), saasSysTenant.getPageSize());
        saasSysTenant.saasSysTenantNoPage();
        Cnd cnd = Cnd.from(dao,saasSysTenant);
        List query = dao.query(SaasTenant.class, cnd, pager);
        TablePageData<SaasTenant> tablePageData = new TablePageData(query, pager);
        return tablePageData;
    }

}
